home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #1 / Amiga Plus 1999 #1.iso / System-Boost / Workbench / BackClock / sources / tracewin.c < prev    next >
C/C++ Source or Header  |  1998-08-10  |  8KB  |  235 lines

  1. /*****************************************************************************
  2.  *
  3.  * Nom:                         tracewin.c
  4.  * Desc:                        fonctions de traçage dans les fenetres
  5.  *
  6.  *
  7.  * version                      : $VER: tracewin.c 2.3ß4 (06.08.98)
  8.  *
  9.  * ver2.3: fill background or transparent
  10.  * ver2.3ß3: CyberGraphics support (beta)
  11.  * ver2.3ß4: BugFixed but beta CGX
  12.  *****************************************************************************
  13.  */ 
  14. #include <exec/memory.h>
  15. #include <graphics/rastport.h>
  16. #include <cybergraphx/cybergraphics.h>
  17. #include <proto/cybergraphics.h>
  18. #include <proto/graphics.h>
  19. #include <proto/exec.h>
  20. #include <math.h>
  21. #include "utils.h"
  22. #include "tracewin.h"
  23.  
  24.  
  25.  
  26.  
  27. struct pt ptSec,
  28.           ptMin,
  29.           ptHeu ;
  30. ULONG mX, mY ;
  31.  
  32. void initwin(idWin * prj) {
  33.   int i ;
  34.   
  35.   mX = prj->backWin.width / 2 ;
  36.   mY = prj->backWin.height / 2 ;
  37.   if (prj->RP1) {
  38.     if(prj->backWin.fill) {
  39.       SetAPen(prj->RP1, prj->backWin.cmap[COL_BAC].reg) ;
  40.       RectFill(prj->RP1, 0, 0, prj->backWin.width-1, prj->backWin.height-1) ;
  41.     }
  42.     SetAPen(prj->RP1, prj->backWin.cmap[COL_TIC].reg) ;                                                       // couleur jaune
  43.     for(i = 0; i < 360; i+=30) {
  44.       /* trace les repères des heures
  45.       */
  46.       Move(prj->RP1, ULONG(cos(PI*i/180.0) * (mX-mX/10L)) + mX, ULONG(sin(PI*i/180.0) * (mY-mY/10L)) + mY) ;
  47.       Draw(prj->RP1, ULONG(cos(PI*i/180.0) * mX) + mX, ULONG(sin(PI*i/180.0) * mY) + mY) ;
  48.     }
  49.     
  50.   }
  51.   /* initalisation des points des aiguilles
  52.    */
  53.   /* secondes
  54.    */
  55.   ptSec.points = 2 ;
  56.   ptSec.fill   = FALSE ;
  57.   ptSec.pt_AI  = NULL ; // needed when freeing
  58.   ptSec.pt_buffer = NULL ; // idem
  59.   ptSec.A[0]   = 0 ;
  60.   ptSec.A[1]   = 180 ;
  61.   ptSec.M[0]   = 5.0 ;
  62.   ptSec.M[1]   = 1.2 ;
  63.   ptSec.angle  = ANGLE_S ;
  64.   /* heures
  65.    */
  66.   ptHeu.points = 5 ;
  67.   ptHeu.fill   = FALSE ;
  68.   ptHeu.pt_AI  = AllocVec(sizeof(struct AreaInfo), MEMF_PUBLIC|MEMF_CLEAR) ;
  69.   ptHeu.pt_buffer = AllocVec(10 * ptHeu.points, MEMF_PUBLIC) ;
  70.   ptHeu.A[0]   = 0 ;
  71.   ptHeu.A[1]   = 100 ;
  72.   ptHeu.A[2]   = 180 ;
  73.   ptHeu.A[3]   = -100 ;
  74.   ptHeu.A[4]   = 0 ;
  75.   ptHeu.M[0]   = 3.0 ;
  76.   ptHeu.M[1]   = 1.1 ;
  77.   ptHeu.M[2]   = 1.2 ;
  78.   ptHeu.M[3]   = 1.1 ;
  79.   ptHeu.M[4]   = 3.0 ;
  80.   ptHeu.angle  = ANGLE_H ;
  81.   
  82.   /* minutes
  83.    */
  84.   ptMin.points =   5 ;
  85.   ptMin.fill   = FALSE ;
  86.   ptMin.pt_AI  = AllocVec(sizeof(struct AreaInfo), MEMF_PUBLIC|MEMF_CLEAR) ;
  87.   ptMin.pt_buffer = AllocVec(10 * ptMin.points, MEMF_PUBLIC) ;
  88.   ptMin.A[0]   =   0 ;
  89.   ptMin.A[1]   =  150 ;
  90.   ptMin.A[2]   = 180 ;
  91.   ptMin.A[3]   = -150 ;
  92.   ptMin.A[4]   =   0 ;
  93.   ptMin.M[0]   =   4 ;
  94.   ptMin.M[1]   =   1.3 ;
  95.   ptMin.M[2]   =   1.2 ;
  96.   ptMin.M[3]   =   1.3 ;
  97.   ptMin.M[4]   =   4 ;
  98.   ptMin.angle  = ANGLE_M ;
  99.   effacer(prj) ;
  100.   retracer(prj) ;
  101.  
  102. }
  103. void free_twin(idWin * prj) {
  104.   if (ptSec.pt_AI)     FreeVec(ptSec.pt_AI) ;
  105.   if (ptSec.pt_buffer) FreeVec(ptSec.pt_buffer) ;
  106.   
  107.   if (ptMin.pt_AI)     FreeVec(ptMin.pt_AI) ;
  108.   if (ptMin.pt_buffer) FreeVec(ptMin.pt_buffer) ;
  109.  
  110.   if (ptHeu.pt_AI)     FreeVec(ptHeu.pt_AI) ;
  111.   if (ptHeu.pt_buffer) FreeVec(ptHeu.pt_buffer) ;
  112.  
  113.  
  114. }
  115.  
  116. void reinit_win(idWin * prj) {
  117.   free_twin(prj) ;
  118.   initwin(prj) ;
  119. }
  120.  
  121. void effacer(idWin * prj) {
  122. //  BltBitMapRastPort(prj->wb->RastPort.BitMap, prj->backWin.posX, prj->backWin.posY, prj->RP1, 0, 0, prj->backWin.width, prj->backWin.height, 0xc0) ;
  123.   UBYTE * pixelarray ;
  124.   if (!CyberGfxBase) {
  125.     WaitBlit() ;
  126.     BltBitMapRastPort(prj->RP1->BitMap, 0,0, prj->RP2, 0, 0, prj->backWin.width, prj->backWin.height, 0xc0) ;
  127.   }else {
  128.     if(pixelarray = AllocVec(prj->backWin.width * prj->backWin.height * 3, MEMF_PUBLIC)) {
  129.       ReadPixelArray(pixelarray, 0, 0, prj->backWin.width*3, prj->RP1, 
  130.                      0, 0, prj->backWin.width, prj->backWin.height,
  131.                      RECTFMT_RGB) ;
  132.       WritePixelArray(pixelarray, 0, 0,prj->backWin.width*3, prj->RP2, 
  133.                       0, 0, prj->backWin.width, prj->backWin.height,
  134.                       RECTFMT_RGB) ;
  135.       FreeVec(pixelarray) ;                                 
  136.     
  137.     }
  138.   }  
  139. }
  140. void retracer(idWin * prj) {
  141.   UBYTE * pixelarray ;
  142.   SetAPen(prj->RP2, prj->backWin.cmap[COL_SEC].reg) ;
  143.   tracerAiguilles(prj, &ptSec, prj->sec, NULL) ;
  144.   SetAPen(prj->RP2, prj->backWin.cmap[COL_MIN].reg) ;
  145.   tracerAiguilles(prj, &ptMin, prj->min, NULL) ;
  146.   SetAPen(prj->RP2, prj->backWin.cmap[COL_HEU].reg) ;
  147.   tracerAiguilles(prj, &ptHeu, prj->heu, prj->min/2) ;
  148.   if (!CyberGfxBase) {
  149.     WaitBlit() ;
  150.     BltBitMapRastPort(prj->RP2->BitMap, 0,0, prj->win->RPort, 0, 0, prj->backWin.width, prj->backWin.height, 0xc0) ;
  151.   }else {
  152.     if(pixelarray = AllocVec(prj->backWin.width * prj->backWin.height * 3, MEMF_PUBLIC)) {
  153.       ReadPixelArray(pixelarray, 0, 0, prj->backWin.width*3, prj->RP2, 
  154.                      0, 0, prj->backWin.width, prj->backWin.height,
  155.                      RECTFMT_RGB) ;
  156.       WritePixelArray(pixelarray, 0, 0,prj->backWin.width*3, prj->win->RPort, 
  157.                       0, 0, prj->backWin.width, prj->backWin.height,
  158.                       RECTFMT_RGB) ;
  159.       FreeVec(pixelarray) ;                                 
  160.     
  161.     }
  162.   }  
  163. }
  164. void tracerAiguilles(idWin * prj, struct pt * ptAigu, UBYTE p_time, UBYTE an_inc) {
  165.   int i ;
  166.   if (ptAigu->pt_AI) {
  167.     // reinitialise AreaInfo
  168.     ptAigu->pt_AI->Count = NULL ; // reset vertices
  169. //    prj->win->RPort->AreaInfo = ptAigu->pt_AI ; // set the areainfo
  170.   }
  171.   
  172.   Move(prj->RP2, mX+(ULONG)(cos(PI*(ptAigu->A[0]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mX-mX/ptAigu->M[0])), 
  173.                         mY+(ULONG)(sin(PI*(ptAigu->A[0]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mY-mY/ptAigu->M[0]))) ;
  174.  
  175.   if (!ptAigu->fill) {
  176.     // tracer sans remplissage
  177.     // no fill
  178.     for(i = 0; i<ptAigu->points; i++)
  179.       Draw(prj->RP2, mX+(ULONG)(cos(PI*(ptAigu->A[i]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mX-mX/ptAigu->M[i])), 
  180.                             mY+(ULONG)(sin(PI*(ptAigu->A[i]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mY-mY/ptAigu->M[i]))) ;
  181.   }else {
  182. /*    // avec remplissage
  183.     // fill
  184.     
  185.     InitArea(ptAigu->pt_AI, ptAigu->pt_buffer, ptAigu->points) ;
  186.     AreaMove(prj->win->RPort, mX+(ULONG)(cos(PI*(ptAigu->A[0]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mX-mX/ptAigu->M[0])), 
  187.                               mY+(ULONG)(sin(PI*(ptAigu->A[0]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mY-mY/ptAigu->M[0]))) ;
  188.  
  189.     for(i = 0; i < ptAigu->points; i++)
  190.       AreaDraw(prj->win->RPort, mX+(ULONG)(cos(PI*(ptAigu->A[i]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mX-mX/ptAigu->M[i])), 
  191.                                 mY+(ULONG)(sin(PI*(ptAigu->A[i]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mY-mY/ptAigu->M[i]))) ;
  192.     
  193.     AreaEnd(prj->win->RPort) ;*/
  194.   }
  195. }
  196.  
  197. void init_bitmap(idWin * prj) {
  198.   /* initialize tmp rastport and bitmap
  199.    */
  200.   UBYTE * pixelarray ;
  201.   prj->RP1 = AllocVec(sizeof(struct RastPort), MEMF_PUBLIC) ;
  202.   prj->RP2 = AllocVec(sizeof(struct RastPort), MEMF_PUBLIC) ; 
  203.   InitRastPort(prj->RP1) ;
  204.   InitRastPort(prj->RP2) ;
  205.   prj->RP1->BitMap = AllocBitMap(prj->backWin.width, prj->backWin.height, prj->wb->RastPort.BitMap->Depth, BMF_CLEAR|BMF_DISPLAYABLE, NULL) ;
  206.   prj->RP2->BitMap = AllocBitMap(prj->backWin.width, prj->backWin.height, prj->wb->RastPort.BitMap->Depth, BMF_CLEAR|BMF_DISPLAYABLE, NULL) ;
  207.   
  208.   if(!CyberGfxBase) {
  209.     WaitBlit() ;
  210.     BltBitMapRastPort(prj->wb->RastPort.BitMap, prj->backWin.posX, prj->backWin.posY, prj->RP1, 0, 0, prj->backWin.width, prj->backWin.height, 0xc0) ;
  211.   }else {
  212.     if(pixelarray = AllocVec(prj->backWin.width * prj->backWin.height * 3, MEMF_PUBLIC)) {
  213.       ReadPixelArray(pixelarray, 0, 0, prj->backWin.width*3, &(prj->wb->RastPort), 
  214.                      prj->backWin.posX, prj->backWin.posY, prj->backWin.width, prj->backWin.height,
  215.                      RECTFMT_RGB) ;
  216.       WritePixelArray(pixelarray, 0, 0,prj->backWin.width*3, prj->RP1, 
  217.                       0, 0, prj->backWin.width, prj->backWin.height,
  218.                       RECTFMT_RGB) ;
  219.       FreeVec(pixelarray) ;                                 
  220.     
  221.     }
  222.   }  
  223.   
  224. }
  225.  
  226. void free_bitmap(idWin * prj) {
  227.   if (prj->RP1 && prj->RP1->BitMap) FreeBitMap(prj->RP1->BitMap) ;
  228.   if (prj->RP2 && prj->RP2->BitMap) FreeBitMap(prj->RP2->BitMap) ;
  229.   if (prj->RP1) FreeVec(prj->RP1) ;
  230.   if (prj->RP2) FreeVec(prj->RP2) ;
  231.   prj->RP1 = prj->RP2 = NULL ;
  232.   
  233. }
  234.  
  235.